﻿<%@ WebHandler Language="C#" Class="GetDay" %>

using System;
using System.Web;
using Dos.Model;
using System.Web.SessionState;
using System.Collections.Generic;
using System.Data;

public class GetDay : IHttpHandler, IRequiresSessionState
{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        if (context.Session["user"] != null)
        {
            Json u = context.Session["user"].ToString();
            string openid = u["openid"];
            List<Days> ds = new List<Days>();
            DataTable dt = DBHelper.GetDataTable(string.Format("select * from temple_days where openid = '{0}'", openid));
            int days = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
            for (int i = 1; i <= days; i++)
            {
                Days d = new Days();
                if (dt != null && dt.Rows.Count > 0)
                {
                    d.Day = i;
                    foreach (DataRow item in dt.Rows)
                    {
                        if (Convert.ToDateTime(item["AddTime"].ToString()).Day == i && int.Parse(item["State"].ToString()) == 1)
                            d.State = true;
                        break;
                    }
                    ds.Add(d);
                }
                else
                {
                    d.Day = i;
                    ds.Add(d);
                }
            }
            context.Response.Write(JsonHelper.ToJson(ds));
        }
    }

    public bool IsReusable
    {
        get { return false; }
    }

    class Days
    {
        private bool _state = false;

        public int Day { set; get; }
        public bool State
        {
            set { _state = value; }
            get { return _state; }
        }
    }
}